import javax.jws.soap.SOAPMessageHandlers;
import java.security.spec.PSSParameterSpec;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Scanner;

/**
 * Created by xiebang
 * Description
 * User:小谢
 * Date:2021-09-17
 * Time:20:44
 */
class Person implements Cloneable{
    public String name;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
public class TestDemo2 {
    //声明了一个异常 throws 会声明一个自定义的异常
    public static void func3() throws ArrayIndexOutOfBoundsException{
        int[] array ={1,2,3,4};
        System.out.println(array[100]);
    }
    public static void main(String[] args) {
        try {
            func3();
        }catch (ArrayIndexOutOfBoundsException e){
            e.printStackTrace();
        }
    }
    public static void main6(String[] args) {
        Scanner scanner = new Scanner(System.in);
        try{
            int n = scanner.nextInt();
            System.out.println(n);
        }catch (InputMismatchException e){
            e.printStackTrace();
        }finally {
            scanner.close();
        }



    }
    public static int fun2(){
        int[] arr ={1,2,3};
        try{
            return 10;
        }catch (NullPointerException e){
            e.printStackTrace();
        }finally {
            return 1;
        }//处理善后工作的，finally永远都是最后被执行的
    }

    public static void main5(String[] args) {
        int i = fun2();
        System.out.println(i);
    }
    public static void main4(String[] args) {
        int[] arr = {1,2,3};
        //int[] arr =null;
        System.out.println("before");
        //System.out.println(arr[100]);

        //当抛出异常之后代码并没有继续执行
        //当没有处理异常的时候 一旦程序发生了异常之后那么这个异常的处理会交给JVM来处理
        //一旦交给了JVM处理，程序会立即终止执行。
        try {
            System.out.println(arr[1]);
            System.out.println("发生异常后不执行了！");//出现异常不会打印
        }catch (ArrayIndexOutOfBoundsException | NullPointerException e){
            e.printStackTrace();
            System.out.println("捕获数组越界了或空指针异常了！");
        } finally {
            System.out.println("finally执行了");
        }
//        catch (NullPointerException e){
//            e.printStackTrace();
//            System.out.println("捕获了一个空指针异常");
//        }
        System.out.println("after");
    }
    public static void func(){
        func();
    }
    public static void main3(String[] args) {
        func();
        //StackOverflowError  栈溢出错误
    }
    public static void main2(String[] args) throws CloneNotSupportedException {
        Person person = new Person();
        Person p2 = (Person) person.clone();//编译时异常
    }

    //每个异常就是一个类
    public static void main1(String[] args) {
        //System.out.println(10/0);
        //ArithmeticException  算术异常
//        int[] array = {1,2,3,4};
//        System.out.println(array[0]);
//        System.out.println(array[10]);
        //ArrayIndexOutOfBoundsException
        Arrays array = null;
        System.out.println(array.equals(1));
    }
}
